﻿#region Creditos

/* Autor: Edilberto Sánchez Forero	*/
/* Email: esanchezfo@gmail.com		*/
/* Licencia: LGPL, Software Libre	*/
/* País: Colombia, Bogotá			*/

#endregion

#region Librerias

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Diagnostics;

using ESF.General;

using ESF.Object.XmlRepresenter;
using ESF.Object.XmlRepresenter.Extensions.Description;
using ESF.General.Text;

#endregion


namespace ESF.Object.SolutionGenerator.Web
{
	public static class ServerControlWebGenerator
	{
		#region Generacion Basica
	
		public static void GenerateWebControls (ref List<ProcessStartInfo> pobjCompileCalls)
		{
			string strBaseFile;
			string strSNKFileName;
			string strSDKFolder;
			string strRuntimeFolder;
			string strMainSourcesDestinationFolder;
			
			TextWriter txtWriter;
			
			ProcessStartInfo proInfo;
			
			DirectoryInfo dirSetSourcesFolder;
			
			
			if (!SolGenerator.GenerateWebControls) { return; }
			
			strMainSourcesDestinationFolder = Path.Combine (SolGenerator.SourcesDestinationFolder, "WebControls");
			
			try
			{
				FileHelper.EnsureRecreateFolder (strMainSourcesDestinationFolder);
				
				foreach (XmlObjectSet objSet in SolGenerator.ObjectSetManager.ObjectSets)
				{
					dirSetSourcesFolder = FileHelper.EnsureFolder (Path.Combine (strMainSourcesDestinationFolder, objSet.Name));
				
					#region Generacion del AsemblyInfo
					
					SolGenerator.GenerateAssemblyInfo (dirSetSourcesFolder, 
						string.Format ("Basic WebControls for {0}.{1} generated by ROSSOX", 
							SolGenerator.Namespace, objSet.Name), 
							string.Format ("WebControls for {0}", SolGenerator.Namespace), 
								SolGenerator.Namespace, objSet.Version);
					
					#endregion			
				
					#region Generacion para archivo SNK
					
					strSNKFileName = string.Format ("{0}{1}{3}{1}{2}.WebControls.{3}.snk", 
						strMainSourcesDestinationFolder, 
						Path.DirectorySeparatorChar, SolGenerator.Namespace, objSet.Name);
					
					proInfo = new ProcessStartInfo ();
			
					SolGenerator.GetRuntimeToolsFolders (out strSDKFolder, out strRuntimeFolder);
					
					proInfo.FileName = string.Format ("\"{0}sn\"", strSDKFolder);
					proInfo.Arguments = string.Format (@"-k ""{0}""", strSNKFileName);
					
					pobjCompileCalls.Add (proInfo);
					
					#endregion
				
					foreach (XmlObject objObj in objSet.Objects)
					{
						strBaseFile = Path.Combine (dirSetSourcesFolder.FullName, objObj.Name + "_{0}.cs");
					
						if (objObj.IsArray)
						{
							// TODO: Crear los controles para manejar arreglos
						}
						else
						{
							txtWriter = File.CreateText (string.Format (strBaseFile, "Edit"));						
							ServerControlWebGenerator.GenerateStartFileWebControl (ref txtWriter, objObj, "Edit");
							ServerControlWebGenerator.GenerateWebControlEdit (objObj, txtWriter);								
							ServerControlWebGenerator.GenerateEndFileWebControl (ref txtWriter);
								
							txtWriter = File.CreateText (string.Format (strBaseFile, "Query"));								
							ServerControlWebGenerator.GenerateStartFileWebControl (ref txtWriter, objObj, "Query");
							ServerControlWebGenerator.GenerateWebControlQuery (objObj, txtWriter);								
							ServerControlWebGenerator.GenerateEndFileWebControl (ref txtWriter);
								
							txtWriter = File.CreateText (string.Format (strBaseFile, "ShortView"));							
							ServerControlWebGenerator.GenerateStartFileWebControl (ref txtWriter, objObj, "ShortView");
							ServerControlWebGenerator.GenerateWebControlShortView (objObj, txtWriter);
							ServerControlWebGenerator.GenerateEndFileWebControl (ref txtWriter);
						}
					}
					
					// TODO: GENERAR CODIGO VALIDO
					// SolGenerator.GenerateCallCompiler (dirSetSourcesFolder.FullName, objSet.Name, "WebControls", strSNKFileName, ref pobjCompileCalls);
				}
			}
			catch (Exception excEx)
			{
				throw new GenericException (GenericException.CRI_SYSTEM_ERROR, "No fue posible generar los controles web", excEx);
			}
		}
		
		#endregion
		
		// TODO: AJUSTAR LOS USINGS ENTRE WEBCONTROLS
		
		#region Funciones de Inicio y Fin de Archivos
		
		private static void GenerateStartFileWebControl (ref TextWriter ptxtWriter, XmlObject pobjObject, string pstrName)
		{
			#region Usings
			
			ptxtWriter.WriteLine ("#region Libraries");
			ptxtWriter.WriteLine ();
			ptxtWriter.WriteLine ("using System;");
			ptxtWriter.WriteLine ("using System.Xml;");
			ptxtWriter.WriteLine ("using System.ComponentModel;");
			ptxtWriter.WriteLine ("using System.Web.UI;");
			ptxtWriter.WriteLine ("using System.Web.UI.WebControls;");
			ptxtWriter.WriteLine ("using System.Collections.Generic;");
			ptxtWriter.WriteLine ("using System.Globalization;");
			ptxtWriter.WriteLine ("using System.Threading;");
			ptxtWriter.WriteLine ();
			ptxtWriter.WriteLine ("using ESF.General;");
			ptxtWriter.WriteLine ();
			
			SolGenerator.AddEntitiesUsings (ref ptxtWriter, pobjObject.Members);
			
			ptxtWriter.WriteLine ("#endregion");	
			ptxtWriter.WriteLine ();
			ptxtWriter.WriteLine ();
			
			#endregion
		
			ptxtWriter.Write ("namespace {0}.WebControls.{1}", SolGenerator.Namespace, pobjObject.SetName);
			ptxtWriter.Write (TextHelper.NL_CO);
			ptxtWriter.Write (@"[ToolboxData (""<{0}:" + pobjObject.Name + "_" + pstrName + @" runat=\""server\""></{0}:" + pobjObject.Name + @">"")]");
			ptxtWriter.Write (TextHelper.NL_1_TAB);
			ptxtWriter.Write ("public class {0}_{1} : WebControl, INamingContainer", pobjObject.Name, pstrName);
			ptxtWriter.Write (TextHelper.NL_1_TAB_CO);
		}
		
		
		private static void GenerateEndFileWebControl (ref TextWriter ptxtWriter)
		{
			ptxtWriter.Write (TextHelper.NL_1_TAB_CC);
			ptxtWriter.Write (TextHelper.NL_CC);
			
			ptxtWriter.Close ();
		}
		
		#endregion
		
		
		#region Edicion
		
		private static void GenerateWebControlEdit (XmlObject pobjObject, TextWriter ptxtWriter)
		{	
			ServerControlWebGenerator.GenerateDeclareSubControls (ref ptxtWriter, pobjObject.Members, true);
			
			ServerControlWebGenerator.GenerateEntityValue (ref ptxtWriter, pobjObject);
			
			ServerControlWebGenerator.GenerateLoadSubControls (ref ptxtWriter, pobjObject.Members, true);
			
			#region Funciones de Vinculo de Controles
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#region Funciones de Vinculo de Controles");
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.Write ("protected override void CreateChildControls ()");
			ptxtWriter.Write (TextHelper.NL_2_TAB_CO);
            ptxtWriter.WriteLine ("this.Controls.Clear ();");
			ptxtWriter.Write (TextHelper.NL_3_TAB);
			ptxtWriter.Write ("this.LoadSubControls ();");
			ptxtWriter.Write (TextHelper.NL_3_TAB);
			ptxtWriter.Write ("");
			ptxtWriter.Write (TextHelper.NL_2_TAB_CC);
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#endregion");
			
			#endregion
						
			ServerControlWebGenerator.GenerateEntityLoad (ref ptxtWriter, pobjObject);
			
			ServerControlWebGenerator.GenerateClearFunction (ref ptxtWriter, pobjObject.Members);
		}
		
		#endregion
		
		
		#region Consulta
		
		private static void GenerateWebControlQuery (XmlObject pobjObject, TextWriter ptxtWriter)
		{
			ServerControlWebGenerator.GenerateDeclareSubControls (ref ptxtWriter, pobjObject.ShortQueryMembers, false);
					
			ServerControlWebGenerator.GenerateEntityValue (ref ptxtWriter, pobjObject);
		
			ServerControlWebGenerator.GenerateLoadSubControls (ref ptxtWriter, pobjObject.ShortQueryMembers, false);
		
			ServerControlWebGenerator.GenerateClearFunction (ref ptxtWriter, pobjObject.ShortQueryMembers);
		}
		
		#endregion
		
		
		#region Presentacion Corta
		
		private static void GenerateWebControlShortView (XmlObject pobjObject, TextWriter ptxtWriter)
		{
			#region SubControles
			
			ptxtWriter.WriteLine ("#region SubControles");
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.Write ("private Label lblResume;");
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.Write ("private LinkButton lnkChoose;");
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("private LinkButton lnkClear;");
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#endregion");

			#endregion

			#region Carga de los SubControles
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#region Funciones de Carga de SubControles");
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.Write ("private string LoadSubControls ()");
			ptxtWriter.Write (TextHelper.NL_2_TAB_CO);
			ptxtWriter.Write ("switch (Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName)");
			ptxtWriter.Write (TextHelper.NL_3_TAB_CO);
			
			ptxtWriter.Write ("default:");
			ptxtWriter.Write (TextHelper.NL_5_TAB);
			ptxtWriter.Write ("lnkChoose.Text = \"Choose\";");
			ptxtWriter.Write (TextHelper.NL_5_TAB);
			ptxtWriter.Write ("lnkClear.Text = \"Clear\";");
			ptxtWriter.Write (TextHelper.NL_5_TAB);
			ptxtWriter.WriteLine ("break;");
			
			ptxtWriter.Write (TextHelper.NL_4_TAB);
			ptxtWriter.Write ("case \"es\":");
			ptxtWriter.Write (TextHelper.NL_5_TAB);
			ptxtWriter.Write ("lnkChoose.Text = \"Seleccionar\";");
			ptxtWriter.Write (TextHelper.NL_5_TAB);
			ptxtWriter.Write ("lnkClear.Text = \"Limpiar\";");
			ptxtWriter.Write (TextHelper.NL_5_TAB);
			ptxtWriter.Write ("break;");
			
			ptxtWriter.Write (TextHelper.NL_3_TAB_CC);
			ptxtWriter.Write (TextHelper.NL_2_TAB_CC);
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#endregion");
			
			#endregion
			
			ServerControlWebGenerator.GenerateEntityValue (ref ptxtWriter, pobjObject);
			
			#region Funciones de Carga
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#region Funciones de Carga");
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.Write ("public void SetValue ({0} pobjValue)", pobjObject.Name);
			ptxtWriter.Write (TextHelper.NL_2_TAB_CO);
			ptxtWriter.Write ("this._Value = pobjValue;");
			ptxtWriter.Write (TextHelper.NL_3_TAB);
			ptxtWriter.Write ("this.lblResume.Text = this._Value.ToShortString ();");
			
			ptxtWriter.Write (TextHelper.NL_2_TAB_CC);
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#endregion");
			
			#endregion
			
			#region Funciones de Vinculo de Controles
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#region Funciones de Vinculo de Controles");
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.Write ("protected override void CreateChildControls ()");
			ptxtWriter.Write (TextHelper.NL_2_TAB_CO);
            ptxtWriter.WriteLine ("this.Controls.Clear ();");
			ptxtWriter.Write (TextHelper.NL_3_TAB);
			ptxtWriter.Write ("this.LoadSubControls ();");
			ptxtWriter.Write (TextHelper.NL_3_TAB);
			ptxtWriter.Write ("");
			ptxtWriter.Write (TextHelper.NL_2_TAB_CC);
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#endregion");
			
			#endregion
			
			#region Funciones de Limpieza
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#region Funciones de Limpieza");
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.Write ("public void Clear ()");
			ptxtWriter.Write (TextHelper.NL_2_TAB_CO);
			ptxtWriter.Write ("this._Value = null;");
			ptxtWriter.Write (TextHelper.NL_3_TAB);
			ptxtWriter.Write ("this.lblResume.Text = string.Empty;");
			ptxtWriter.Write (TextHelper.NL_2_TAB_CC);
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#endregion");
			
			#endregion
		}
		
		#endregion
		
		
		#region Funciones Generales

		private static void GenerateEntityLoad (ref TextWriter ptxtWriter, XmlObject pobjObject)
		{	
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#region Funciones de Carga");
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.Write ("public {0} GetValue ()", pobjObject.Name);
			ptxtWriter.Write (TextHelper.NL_2_TAB_CO);
			ptxtWriter.Write ("return this._Value;");
			ptxtWriter.WriteLine (TextHelper.NL_2_TAB_CC);
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.Write ("public void SetValue ({0} pobjValue)", pobjObject.Name);
			ptxtWriter.Write (TextHelper.NL_2_TAB_CO);
			ptxtWriter.WriteLine ("this._Value = value;");
			ptxtWriter.Write (TextHelper.NL_3_TAB);
			ptxtWriter.WriteLine ("this.Clear ();");
			
			foreach (XmlMember objMember in pobjObject.Members)
			{
				ptxtWriter.Write (TextHelper.NL_3_TAB);
				ptxtWriter.Write ("if (!this.IsNull_{0})", objMember.Name);
				ptxtWriter.Write (TextHelper.NL_3_TAB_CO);
				
				ptxtWriter.Write ("this.cnt{0}.", objMember.Name);
			
				switch (objMember.Type)
				{
					case ValueTypes.Custom:
						ptxtWriter.Write ("SetValue (this._Value.{0})", objMember.Name);
						break;
						
					case ValueTypes.Bool:
						ptxtWriter.Write ("Checked = this._Value.{0}.Value", objMember.Name);
						break;
				
					// TODO: Importante revisar si crear un control basado en listas especializado para date y datetime
					case ValueTypes.Date:
						ptxtWriter.Write ("Text = this._Value.{0}.ToString ()", objMember.Name);
						break;
				
					case ValueTypes.DateTime:
						ptxtWriter.Write ("Text = this._Value.{0}.ToString ()", objMember.Name);
						break;
					
					default:
						ptxtWriter.Write ("Text = this._Value.{0}", objMember.Name);
						break;
				}
				
				ptxtWriter.Write (";");
				ptxtWriter.Write (TextHelper.NL_3_TAB_CC);
			}
			
			ptxtWriter.Write (TextHelper.NL_2_TAB_CC);
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#endregion");
		}


		private static void GenerateEntityValue (ref TextWriter ptxtWriter, XmlObject pobjObject)
		{
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#region Entidad del Control");
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("private {0} _Value;", pobjObject.Name);
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#endregion");
		}


		private static void GenerateDeclareSubControls (ref TextWriter ptxtWriter, List<XmlMember> pobjMembers, bool pblnIncludeRequiredValidators)
		{
			ptxtWriter.WriteLine ("#region SubControles");
		
			foreach (XmlMember objMember in pobjMembers)
			{
				ptxtWriter.Write (TextHelper.NL_2_TAB);
				ptxtWriter.Write ("private Label lblTitle{0};", objMember.Name);
				
				if (objMember.IsCustom)
				{
					ptxtWriter.Write (TextHelper.NL_2_TAB);
					ptxtWriter.Write ("private {0}_ShortView cnt{0};", objMember.Name);
				}
				else
				{
					ptxtWriter.Write (TextHelper.NL_2_TAB);
					ptxtWriter.Write ("private Label lblExample{0};", objMember.Name);
				
					ptxtWriter.Write (TextHelper.NL_2_TAB);
					ptxtWriter.Write ("private ");
					
					if (objMember.Type == ValueTypes.Bool)
					{
						ptxtWriter.Write ("CheckBox chk{0};", objMember.Name);
					}
					else
					{
						ptxtWriter.Write ("TextBox txt{0};", objMember.Name);
						
						if (objMember.RegEx != null)
						{
							ptxtWriter.Write (TextHelper.NL_2_TAB);
							ptxtWriter.Write ("private RegularExpressionValidator rev{0};", objMember.Name);
						}
						
						if (objMember.Required && pblnIncludeRequiredValidators)
						{
							ptxtWriter.Write (TextHelper.NL_2_TAB);
							ptxtWriter.Write ("private RequiredFieldValidator rfv{0};", objMember.Name);
						}						
					}
				}
				
				ptxtWriter.WriteLine ();
			}
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#endregion");
		}
	
		
		private static void GenerateClearFunction (ref TextWriter ptxtWriter, List<XmlMember> pobjMembers)
		{
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#region Funcion de Limpieza");
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.Write ("public void Clear ()");
			ptxtWriter.Write (TextHelper.NL_2_TAB_CO);
			ptxtWriter.WriteLine ("this._Value = null;");
			
			foreach (XmlMember objMember in pobjMembers)
			{
				ptxtWriter.Write (TextHelper.NL_3_TAB);
				ptxtWriter.Write ("this.");
			
				switch (objMember.Type)
				{
					case ValueTypes.Custom:
						ptxtWriter.Write ("cnt{0}.Clear ()", objMember.Name);
						break;
					
					case ValueTypes.Bool:
						ptxtWriter.Write ("chk{0}.Checked = false", objMember.Name);
						break;
						
					default:
						ptxtWriter.Write ("txt{0}.Text = string.Empty", objMember.Name);
						break;
				}
				
				ptxtWriter.Write (";");
			}
			
			ptxtWriter.Write (TextHelper.NL_2_TAB_CC);
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.Write ("#endregion");
		}
		
		
		private static void GenerateLoadSubControls (ref TextWriter ptxtWriter, List<XmlMember> pobjMembers, bool pblnIncludeRequiredValidators)
		{	
			string strTempISOCode;
			string strTempPrefix;
			
			ushort? shrMaxLength;
			
			StringBuilder strTempLabels;
		
			XmlMemberDescription objDesc;
			
			Regex objRegEx; 
			
			Dictionary <string,StringBuilder> strISOLanguageCodeAsignations;
			
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#region Funciones de Carga de SubControles");
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.Write ("private string LoadSubControls ()");
			ptxtWriter.Write (TextHelper.NL_2_TAB_CO);
			
			strISOLanguageCodeAsignations = new Dictionary<string,StringBuilder> ();
			
			foreach (XmlMember objMember in pobjMembers)
			{	
				ptxtWriter.Write ("this.lblTitle{0} = new Label ();", objMember.Name);
				ptxtWriter.Write (TextHelper.NL_3_TAB);
				
				if (objMember.IsCustom)
				{
					strTempPrefix = "cnt";
					ptxtWriter.Write ("this.cnt{0} = new {0}_ShortView ();", objMember.Name);	
				}
				else
				{
					ptxtWriter.Write ("this.lblExample{0} = new Label ();", objMember.Name);
					ptxtWriter.Write (TextHelper.NL_3_TAB);
					
					if (objMember.Type == ValueTypes.Bool)
					{
						strTempPrefix = "chk";
						ptxtWriter.Write ("this.chk{0} = new CheckBox ();", objMember.Name);
						ptxtWriter.Write (TextHelper.NL_3_TAB);
					}
					else
					{
						strTempPrefix = "txt";
						ptxtWriter.Write ("this.txt{0} = new TextBox ();", objMember.Name);
						ptxtWriter.Write (TextHelper.NL_3_TAB);
					
						shrMaxLength = objMember.ApplicableMaxLength;
						
						if (shrMaxLength != null)
						{
							ptxtWriter.Write ("this.txt{0}.MaxLength = {1};", objMember.Name, objMember.ApplicableMaxLength.Value);
						}
						
						objRegEx = objMember.RegEx;
				
						if (objRegEx != null)
						{
							ptxtWriter.Write (TextHelper.NL_3_TAB);
							ptxtWriter.Write ("this.rev{0} = new RegularExpressionValidator ();", objMember.Name);
							ptxtWriter.Write (TextHelper.NL_3_TAB);
							ptxtWriter.Write ("this.rev{0}.Text = \"*\";", objMember.Name);
							ptxtWriter.Write (TextHelper.NL_3_TAB);
							ptxtWriter.Write ("this.rev{0}.ValidationExpression = @\"{1}\";", objMember.Name, objRegEx.ToString ());
							ptxtWriter.Write (TextHelper.NL_3_TAB);
							ptxtWriter.Write ("this.rev{0}.ControlToValidate = this.{1}{0}.ID;", objMember.Name, strTempPrefix);
						}
						
						if (objMember.Required && pblnIncludeRequiredValidators)
						{
							ptxtWriter.Write (TextHelper.NL_3_TAB);
							ptxtWriter.Write ("this.rfv{0} = new RequiredFieldValidator ();", objMember.Name);
							ptxtWriter.Write (TextHelper.NL_3_TAB);
							ptxtWriter.Write ("this.rfv{0}.Text = \"*\";", objMember.Name);
							ptxtWriter.Write (TextHelper.NL_3_TAB);
							ptxtWriter.Write ("this.rfv{0}.ControlToValidate = this.{1}{0}.ID;", objMember.Name, strTempPrefix);
						}
					}
				}
				
				ptxtWriter.Write (TextHelper.NL_3_TAB);
			
				foreach (string strISOLanguageCode in objMember.DescriptionsISOLanguageCodes)
				{
					strTempLabels = new StringBuilder ();
					
					objDesc = objMember.GetDescription (strISOLanguageCode);
					
					strTempLabels.AppendFormat ("this.lblTitle{1}.Text = \"{2}\";{0}", 
						TextHelper.NL_5_TAB, objMember.Name, objDesc.Label.Replace ("\"", @"\"""));
						
					if (!string.IsNullOrEmpty (objDesc.Example))
					{
						strTempLabels.AppendFormat ("this.lblExample{1}.Text = \"{2}\";{0}", 
							TextHelper.NL_5_TAB, objMember.Name, objDesc.Label.Replace ("\"", @"\"""));
					}
					
					if (!string.IsNullOrEmpty (objDesc.Description))
					{
						strTempLabels.AppendFormat ("this.{1}{2}.ToolTip = \"{3}\";{0}", 
							TextHelper.NL_5_TAB, strTempPrefix, objMember.Name, 
							objDesc.Description.Replace ("\"", @"\"""));
					}
					
					if (objDesc.Default)
					{	
						strTempISOCode = string.Empty;
					}
					else
					{
						strTempISOCode = strISOLanguageCode;
					}
					
					if (strISOLanguageCodeAsignations.ContainsKey (strTempISOCode))
					{
						strISOLanguageCodeAsignations [strTempISOCode].Append (strTempLabels.ToString ());
					}
					else
					{
						strISOLanguageCodeAsignations.Add (strTempISOCode, new StringBuilder (strTempLabels.ToString ()));
					}
				}
				
				ptxtWriter.Write (TextHelper.NL_3_TAB);
			}
			
			ptxtWriter.Write ("switch (Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName)");
			ptxtWriter.Write (TextHelper.NL_3_TAB_CO);
		
			foreach (KeyValuePair<string, StringBuilder> strAsignations in strISOLanguageCodeAsignations)
			{
				if (string.IsNullOrEmpty (strAsignations.Key))
				{
					ptxtWriter.Write ("default");
				}
				else
				{
					ptxtWriter.Write ("case \"{0}\"", strAsignations.Key);
				}
				
				ptxtWriter.Write (":");
				ptxtWriter.Write (TextHelper.NL_5_TAB);
				ptxtWriter.Write (strAsignations.Value.ToString ());
				ptxtWriter.WriteLine ("break;");
				ptxtWriter.Write (TextHelper.NL_4_TAB);
			}
			
			ptxtWriter.Write (TextHelper.NL_3_TAB_CC);
			ptxtWriter.Write (TextHelper.NL_2_TAB_CC);
			
			ptxtWriter.Write (TextHelper.NL_2_TAB);
			ptxtWriter.WriteLine ("#endregion");
		}

		#endregion
	}
}
